package org.example.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.example.datasource.DynamicSqlBuilder;

import java.util.List;
import java.util.Map;

@Mapper
public interface DynamicSqlMapper {

    // 使用Provider方式动态生成SQL
    @SelectProvider(type = DynamicSqlBuilder.class, method = "buildQuerySql")
    List<Map<String, Object>> executeQuery(@Param("rawSql") String rawSql);

    // 获取表结构元数据
    @Select("SELECT COLUMN_NAME, DATA_TYPE, COLUMN_COMMENT " +
            "FROM information_schema.COLUMNS " +
            "WHERE TABLE_SCHEMA = (SELECT DATABASE()) AND TABLE_NAME = #{tableName}")
    List<Map<String, Object>> getTableMetaData(String tableName);
}
